package com.spgf.controller.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.archtecture.model.exceptions.NegocioException;
import com.spgf.controller.R;
import com.spgf.controller.RelatorioCategoriaSwipeActivity;
import com.spgf.model.rn.LancamentoRN;
import com.spgf.model.rn.OrcamentoRN;
import com.spgf.model.utils.AndroidUtil;

public class ResumoInicialFragment extends Fragment implements Button.OnClickListener {

	private TextView	lblValorApurado;

	private TextView	lblValorEsperado;

	private TextView	lblValorTotal;

	private View		rootView;

	@Override
	public void onClick(View pView) {

		if (pView.getId() == R.id.btn_resumo_relatorio_categoria) {
			Intent lIntent = new Intent(getActivity(), RelatorioCategoriaSwipeActivity.class);
			startActivity(lIntent);
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		rootView = inflater.inflate(R.layout.activity_resumo, container, false);

		try {

			Double lValorApurado = new LancamentoRN(rootView.getContext()).calcularValorTotal();
			Double lValorEsperado = new OrcamentoRN(rootView.getContext()).calcularValorEsperado();
			Double lValorTotal = lValorApurado - lValorEsperado;

			lblValorApurado = (TextView) rootView.findViewById(R.id.lbl_resumo_apurado_valor);
			lblValorApurado.setText(AndroidUtil.obterValorMonetario(lValorApurado));

			lblValorEsperado = (TextView) rootView.findViewById(R.id.lbl_resumo_esperado_valor);
			lblValorEsperado.setText(AndroidUtil.obterValorMonetario(lValorEsperado));

			lblValorTotal = (TextView) rootView.findViewById(R.id.lbl_resumo_total_valor);
			lblValorTotal.setText(AndroidUtil.obterValorMonetario(lValorTotal));

			((Button) rootView.findViewById(R.id.btn_resumo_relatorio_categoria)).setOnClickListener(this);

		} catch (NegocioException ne) {

		}
		return rootView;
	}
}